package com.wlz.files.download;

/**
 * @author wlz
 * @date 2024-04-23  11:35
 */
public class Test {

    private static final long MAX_MAP_SIZE = 1610612736L;

    public static void main(String[] args) {
        // token:54839b68-341b-4205-b44f-43fc2fda9d7b,FileInfo:UpgradeFileInfo(id=52461820-4390-4ea5-884a-304ed3410306, fileSize=20269539820,
        // md5=347b8038dd4dd5d36c33318615e4e835, fileName=ADCBD0701000001S005C211RT6-ALL.zip,
        // fullName=/home/fota/share/upgrade-package-done-file/20240423/fdd682e6-ddd5-4e18-8834-e3d05734089e/ADCBD0701000001S005C211RT6-ALL.zip),
        // FileRange:FileRange(token=54839b68-341b-4205-b44f-43fc2fda9d7b, range=bytes=14092861440-14134804479, fileSize=20269539820,
        // from=14092861440, contentLength=41943040, partial=true)


        long position = 1006632936; // fileRange.getFrom();
        long size = 41943039; //fileRange.getContentLength();
        long total = 21453496460L; // fileInfo.getFileSize();

        // 分块
        int chunk = (int) (position / MAX_MAP_SIZE);
        long readPosition = position % MAX_MAP_SIZE;
        while (size > 0) {
            long readSize = size;
            if (size > MAX_MAP_SIZE - readPosition) {
                readSize = MAX_MAP_SIZE - readPosition;
            }
            System.out.println("fullname: " + total + " " + chunk + " " + readPosition + " " + readSize);
            size = size - readSize;
            readPosition = 0;
            chunk++;
        }
        System.out.println(chunk);

    }
}
